function [] = Scattering(egnalt,egnneu,max,min)
%SCATTERING Summary of this function goes here
%   Detailed explanation goes here
fieldfalt=RemoveHPforScattering(fieldnames(egnalt.HPs));
fieldfneu=RemoveHPforScattering(fieldnames(egnneu.HPs));
fieldf=RemoveHPfromRestrictionsFront(fieldnames(egnneu.HPs));
fieldr=RemoveHPfromRestrictionsRear(fieldnames(egnneu.HPs));
for k=1:numel(fieldfalt)
    for j=1:3
        Coordinates(1,j,k)=egnalt.HPs.(fieldfalt{k})(j);
        Coordinates(2,j,k)=egnneu.HPs.(fieldfneu{k})(j);
    end
end

figure(1)
hold on
grid on
for i=1:numel(fieldfalt)
    scatter3(Coordinates(1,1,i),Coordinates(1,2,i),Coordinates(1,3,i),'b');
    scatter3(Coordinates(2,1,i),Coordinates(2,2,i),Coordinates(2,3,i),'r');
    plot3(Coordinates(:,1,i),Coordinates(:,2,i),Coordinates(:,3,i),'g');
end
%% Front Restrictions
for i=1:numel(fieldf)
    square_rear=[min.front.xmin.(fieldf{i}),  min.front.ymin.(fieldf{i}),  min.front.zmin.(fieldf{i});...
                 min.front.xmin.(fieldf{i}),  max.front.ymax.(fieldf{i}),  min.front.zmin.(fieldf{i});...
                 min.front.xmin.(fieldf{i}),  max.front.ymax.(fieldf{i}),  max.front.zmax.(fieldf{i});...
                 min.front.xmin.(fieldf{i}),  min.front.ymin.(fieldf{i}),  max.front.zmax.(fieldf{i});...
                 min.front.xmin.(fieldf{i}),  min.front.ymin.(fieldf{i}),  min.front.zmin.(fieldf{i})];
	plot3(square_rear(:,1),square_rear(:,2),square_rear(:,3),'k')
    square_front=[max.front.xmax.(fieldf{i}),  min.front.ymin.(fieldf{i}),  min.front.zmin.(fieldf{i});...
                 max.front.xmax.(fieldf{i}),  max.front.ymax.(fieldf{i}),  min.front.zmin.(fieldf{i});...
                 max.front.xmax.(fieldf{i}),  max.front.ymax.(fieldf{i}),  max.front.zmax.(fieldf{i});...
                 max.front.xmax.(fieldf{i}),  min.front.ymin.(fieldf{i}),  max.front.zmax.(fieldf{i});...
                 max.front.xmax.(fieldf{i}),  min.front.ymin.(fieldf{i}),  min.front.zmin.(fieldf{i})];
	plot3(square_front(:,1),square_front(:,2),square_front(:,3),'k')
    
    square_top=[min.front.xmin.(fieldf{i}),  min.front.ymin.(fieldf{i}),  max.front.zmax.(fieldf{i});...
                 min.front.xmin.(fieldf{i}),  max.front.ymax.(fieldf{i}),  max.front.zmax.(fieldf{i});...
                 max.front.xmax.(fieldf{i}),  max.front.ymax.(fieldf{i}),  max.front.zmax.(fieldf{i});...
                 max.front.xmax.(fieldf{i}),  min.front.ymin.(fieldf{i}),  max.front.zmax.(fieldf{i});...
                 min.front.xmin.(fieldf{i}),  min.front.ymin.(fieldf{i}),  max.front.zmax.(fieldf{i})];
	plot3(square_top(:,1),square_top(:,2),square_top(:,3),'k')    
    
    square_bottom=[min.front.xmin.(fieldf{i}),  min.front.ymin.(fieldf{i}),  min.front.zmin.(fieldf{i});...
                 min.front.xmin.(fieldf{i}),  max.front.ymax.(fieldf{i}),  min.front.zmin.(fieldf{i});...
                 max.front.xmax.(fieldf{i}),  max.front.ymax.(fieldf{i}),  min.front.zmin.(fieldf{i});...
                 max.front.xmax.(fieldf{i}),  min.front.ymin.(fieldf{i}),  min.front.zmin.(fieldf{i});...
                 min.front.xmin.(fieldf{i}),  min.front.ymin.(fieldf{i}),  min.front.zmin.(fieldf{i})];
    plot3(square_bottom(:,1),square_bottom(:,2),square_bottom(:,3),'k')
    

%% Rear Restrictions
for i=1:numel(fieldr)
    square_rear=[min.rear.xmin.(fieldr{i}),  min.rear.ymin.(fieldr{i}),  min.rear.zmin.(fieldr{i});...
                 min.rear.xmin.(fieldr{i}),  max.rear.ymax.(fieldr{i}),  min.rear.zmin.(fieldr{i});...
                 min.rear.xmin.(fieldr{i}),  max.rear.ymax.(fieldr{i}),  max.rear.zmax.(fieldr{i});...
                 min.rear.xmin.(fieldr{i}),  min.rear.ymin.(fieldr{i}),  max.rear.zmax.(fieldr{i});...
                 min.rear.xmin.(fieldr{i}),  min.rear.ymin.(fieldr{i}),  min.rear.zmin.(fieldr{i})];
	plot3(square_rear(:,1),square_rear(:,2),square_rear(:,3),'k')
    square_front=[max.rear.xmax.(fieldr{i}),  min.rear.ymin.(fieldr{i}),  min.rear.zmin.(fieldr{i});...
                 max.rear.xmax.(fieldr{i}),  max.rear.ymax.(fieldr{i}),  min.rear.zmin.(fieldr{i});...
                 max.rear.xmax.(fieldr{i}),  max.rear.ymax.(fieldr{i}),  max.rear.zmax.(fieldr{i});...
                 max.rear.xmax.(fieldr{i}),  min.rear.ymin.(fieldr{i}),  max.rear.zmax.(fieldr{i});...
                 max.rear.xmax.(fieldr{i}),  min.rear.ymin.(fieldr{i}),  min.rear.zmin.(fieldr{i})];
	plot3(square_front(:,1),square_front(:,2),square_front(:,3),'k')
    
    square_top=[min.rear.xmin.(fieldr{i}),  min.rear.ymin.(fieldr{i}),  max.rear.zmax.(fieldr{i});...
                 min.rear.xmin.(fieldr{i}),  max.rear.ymax.(fieldr{i}),  max.rear.zmax.(fieldr{i});...
                 max.rear.xmax.(fieldr{i}),  max.rear.ymax.(fieldr{i}),  max.rear.zmax.(fieldr{i});...
                 max.rear.xmax.(fieldr{i}),  min.rear.ymin.(fieldr{i}),  max.rear.zmax.(fieldr{i});...
                 min.rear.xmin.(fieldr{i}),  min.rear.ymin.(fieldr{i}),  max.rear.zmax.(fieldr{i})];
	plot3(square_top(:,1),square_top(:,2),square_top(:,3),'k')    
    
    square_bottom=[min.rear.xmin.(fieldr{i}),  min.rear.ymin.(fieldr{i}),  min.rear.zmin.(fieldr{i});...
                 min.rear.xmin.(fieldr{i}),  max.rear.ymax.(fieldr{i}),  min.rear.zmin.(fieldr{i});...
                 max.rear.xmax.(fieldr{i}),  max.rear.ymax.(fieldr{i}),  min.rear.zmin.(fieldr{i});...
                 max.rear.xmax.(fieldr{i}),  min.rear.ymin.(fieldr{i}),  min.rear.zmin.(fieldr{i});...
                 min.rear.xmin.(fieldr{i}),  min.rear.ymin.(fieldr{i}),  min.rear.zmin.(fieldr{i})];
    plot3(square_bottom(:,1),square_bottom(:,2),square_bottom(:,3),'k')
end
axis equal;
end

